
* This code generates results (3 figures, 13 tables) in the paper 
* "Liquidity Restrictions, Runs, and Central Bank Interventions: Evidence from Money Market Funds" (RFS forthcoming)
* by Lei Li, Yi Li, Marco Macchiavelli, and Xing (Alex) Zhou



* the main data sets include:
* 	data_crisis20_final.dta
* 	data_crisis08_final.dta
* 	data_mmlf_final.dta






/*************************************/
/*** Figure 1: Yield spreads on CP/CD ***/
/*************************************/

/*** Figure 1b: yield spreads on CP/CDs ***/
import excel "cpcd_spread.xlsx", sheet("Sheet1") firstrow
rename AAnonfin AAnonfin
rename A2P2 A2P2
* calculate moving average
sort date
foreach s in AAnonfin A2P2 ABCP NCD{
	gen `s'_3ma=(`s'[_n-1]+`s'+`s'[_n+1])/3
	}
drop if date>td(09apr2020) 
* plot the chart
#delimit ;
twoway line AAnonfin_3ma date, lpattern(solid) lcolor(red) lwidth(thick)
	|| line ABCP_3ma date , lpattern(dash) lcolor(blue) lwidth(thick)
	|| line NCD_3ma date, lpattern(shortdash) lcolor(black) lwidth(thick)
	||, xline(21997, lcolor(gray))
	   ylabel(0(40)220,angle(horizontal))
	   xlabel(21959(7)22016,labsize(medsmall))
	   tlabel(,format(%tdMon_dd))
	   legend(order (1 "AA nonfinancial CP" 
	   2 "ABCP" 3 "Negotiable CD") rows(1))
	   graphregion(color(white)) bgcolor(white)
	   note(Note: Yield spreads are calculated as three-day moving averages.)
	   title("Yield spreads on 1-month CP and NCDs, in basis points",
	      size (medium) color(black));
#delimit cr
graph save "Graph" "cpcd_spread.gph"
clear





/*****************************/
/*** Figure 2: runs on MMFs ***/
/*****************************/

/***Figure 2a: Flow for different types of funds***/
use data_mmlf_final
keep if date>=td(06feb2020) & date<=td(03apr2020)
gen type="inst" if domestic & inst
replace type="retail" if domestic & ~inst
replace type="offshore" if offshore & inst
drop if type==""
collapse (sum)AUM=asset_d, by(date type)
replace AUM=AUM/1000 /* in billion */
reshape wide AUM,i(date) j(type) string
* normalize AUM to be 1 on March 6
foreach t in inst retail offshore{
gen A`t'=AUM`t'/AUM`t'[22]
}
* plot
#delimit ;
twoway line Ainst date, lpattern(solid) lcolor(red) lwidth(thick)
	||  line Aoffshore date , lpattern(dash) lcolor(black) lwidth(thick)
	||  line Aretail date , lpattern(longdash) lcolor(blue) lwidth(thick)
	||, xline(21997, lcolor(gray))
	   ylabel(0.65(0.05)1.05,angle(horizontal))
	   xlabel(21951(10)22011,labsize(medsmall))
	   tlabel(,format(%tdMon_dd))
	   legend(order (1 "Institutional" 2 "Instit. offshore USD" 3 "Retail") rows(1))
	   graphregion(color(white)) bgcolor(white)
	   note("Note: Assets for each fund type are normalized to one on Mar 6, 2020.")
	   title("Prime MMF assets: by fund type",
	      size (medium) color(black));
#delimit cr
graph save "Graph" "AUMbyfund.gph"
clear



/***Figure 2b: Flow for different crises***/
import excel "flowbycrisis.xlsx", sheet("Sheet1") firstrow clear
twoway line A20 Days || line A11 Days || line A08 Days
* plot 08 &20
#delimit ;
twoway line A20 Days if D<=20, lpattern(solid) lcolor(red) lwidth(vthick)
	||  line A08 Days if D<=20, lpattern(longdash) lcolor(black) lwidth(thick)
	||, xline(0, lcolor(gray))
	   ylabel(0.65(0.05)1.05,angle(horizontal))
	   xlabel(-20(5)20,labsize(medsmall))
	   xtitle("Business days since start of crisis")
	   legend(order (1 "2020" 2 "2008") rows(1))
	   graphregion(color(white)) bgcolor(white)
	note("Note: AUMs are normalized to one for Sep 9, 2008 and Mar 6, 2020.",size(medium))
	   title("Normalized AUMs of institutional prime MMFs: by crisis",
	      size (medium) color(black));
#delimit cr
graph save "Graph" "AUMbycrisis.gph"
clear





/*********************************************/
/*** Figure 3: WLA levels and prime fund runs ***/
/*********************************************/

/***Figure 3a: WLA time series***/
use data_crisis20_final
keep if date>=td(06feb2020) & date<=td(03apr2020)
collapse (mean) wla_d dla_d, by (date)
* plot
#delimit ;
twoway line wla_d date, lpattern(solid) lcolor(red) lwidth(thick)
	||, xline(21997, lcolor(gray))
	   ylabel(40(2)50,angle(horizontal))
	   xlabel(21951(10)22011,labsize(medsmall))
	   ytitle("")
	   tlabel(,format(%tdMon_dd))
	   graphregion(color(white)) bgcolor(white)
	   title("Average WLA of institutional prime MMFs (in percent)",
	      size (medium) color(black));
#delimit cr
graph save "Graph" "wla.gph"
clear



/***Figure 3b: Flow for high and low WLA funds***/
use data_crisis20_final
keep if date>=td(06feb2020) & date<=td(03apr2020)
* three groups
gen group="top" if wla_d_l2>50 & wla_d_l2<.
replace group="mid" if wla_d_l2<=50 & wla_d_l2>40
replace group="btm" if wla_d_l2<=40
drop if group==""
collapse (mean) pflow_w [aw=asset_d], by (date group)
rename pflow_w pflow
reshape wide pflow,i(date) j(group) string
* calculate cumulative flows
foreach g in btm mid top{
gen aum_`g'=1 if _n==1
replace aum_`g'=aum_`g'[_n-1]*(1+pflow`g'/100) if _n>1
}
* normalize to 1 on March 6
foreach g in btm mid top{
gen A_`g'=aum_`g'/aum_`g'[21]
}
* plot
#delimit ;
twoway line A_btm date, lpattern(solid) lcolor(red) lwidth(thick)
	||  line A_mid date , lpattern(dash) lcolor(black) lwidth(thick)
	||  line A_top date , lpattern(longdash) lcolor(blue) lwidth(thick)
	||, xline(21998, lcolor(gray))
	   ylabel(0.65(0.05)1.05,angle(horizontal))
	   xlabel(21951(10)22011,labsize(medsmall))
	   tlabel(,format(%tdMon_dd))
	   legend(order (1 "WLA<=40" 2 "WLA 40-50" 3 "WLA>50") rows(1))
	   graphregion(color(white)) bgcolor(white)
	note("Note: Assets in each WLA group are normalized to one on Mar 6, 2020.")
	   title("Institutional prime MMF assets: by lagged WLA levels",
	      size (medium) color(black));
#delimit cr
graph save "Graph" "AUMbyWLA.gph"
clear






/***************************************************/
/*** Table 1: Fund WLA levels and crisis outflows ***/
/***************************************************/

use data_crisis20_final

/*** Regressions ***/
reghdfe pflow_w crisis##c.wla_d_l2 ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m1
reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m2
reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m3
reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	c.wla_d_l2##(1.PT_m2w 1.PT_m3w) ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m4
reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	c.wla_d_l2##(1.PT_m2w 1.PT_m3w) ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m5

*Output results
esttab m1 m2 m3 m4 m5, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(pflow_lag_w  1.PT_m3w 1.PT_m2w 1.crisis ///
	wla_d_l2  1.PT_m3w#c.wla_d_l2 ///
	 1.PT_m2w#c.wla_d_l2 1.crisis#c.wla_d_l2 ) ///
	 keep(pflow_lag_w  1.PT_m3w 1.PT_m2w 1.crisis ///
	wla_d_l2  1.PT_m3w#c.wla_d_l2 ///
	 1.PT_m2w#c.wla_d_l2 1.crisis#c.wla_d_l2)
drop _est_m*	
clear






/***********************************************************************/
/*** Table 2: Acceleration of redemptions when WLA is closer to 30% ***/
/***********************************************************************/

use data_crisis20_final

/*** Regressions ***/
reghdfe pflow_w crisis wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m1
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w crisis wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m2
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
        PT_m2w_wla_le40 PT_m2w_wla_40_50 PT_m2w_wla_ge50 ///
	PT_m3w_wla_le40 PT_m3w_wla_40_50 PT_m3w_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m3
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	  pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	  if w20, vce(cluster f_id date) noabsorb
est store m4
qui:test crisis_wla_low=crisis_wla_high
display r(p)

reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	  pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	  if w20, vce(cluster f_id date) absorb(date)
est store m5
qui:test crisis_wla_low=crisis_wla_high
display r(p)

reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
        PT_m2w_wla_low  PT_m2w_wla_high ///
	PT_m3w_wla_low  PT_m3w_wla_high ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m6
qui:test crisis_wla_low=crisis_wla_high
display r(p)

*Output results
esttab m1 m2 m3 m4 m5 m6, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high) ///
	 keep(crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high)
drop _est_m*	
clear





/***********************************************************************/
/*** Table 3: Are redemptions driven by asset illiquidity? DLA vs. WLA***/
/***********************************************************************/

use data_crisis20_final

/*** Regressions ***/
reghdfe pflow_w  crisis##c.dla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m1
reghdfe pflow_w  crisis##c.dla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m2
reghdfe pflow_w pflow_lag_w ///
	crisis##c.wla_d_l2 crisis##c.dla_d_l2 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m3
reghdfe pflow_w pflow_lag_w ///
	crisis##c.wla_d_l2 crisis##c.dla_d_l2 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m4
*Output results 
esttab m1 m2 m3 m4, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(1.crisis dla_d_l2 1.crisis#c.dla_d_l2  ///
	wla_d_l2 1.crisis#c.wla_d_l2 ) ///
	keep(1.crisis dla_d_l2 1.crisis#c.dla_d_l2  ///
	wla_d_l2 1.crisis#c.wla_d_l2 )
drop _est_m*	
clear






/*******************************************************************/
/*** Table 4: Do redemptions accelerate when DLA is closer to 10%?***/
/*******************************************************************/
use data_crisis20_final

/*** Generate variables ***/
gen dla_le20=dla_d_l2*cond(dla_d_l2<=20,1,0)
gen dla_20_30=dla_d_l2*cond(dla_d_l2>20 & dla_d_l2<=30,1,0)
gen dla_ge30=dla_d_l2*cond(dla_d_l2>30,1,0)
g crisis_dla_le20=crisis*dla_le20
g crisis_dla_20_30=crisis*dla_20_30
g crisis_dla_ge30=crisis*dla_ge30


/*** Regressions ***/
reghdfe pflow_w crisis dla_le20 crisis_dla_le20 ///
	dla_20_30 crisis_dla_20_30 dla_ge30 crisis_dla_ge30 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m1
qui:test crisis_dla_le20=crisis_dla_20_30
display r(p)
qui:test crisis_dla_le20=crisis_dla_ge30
display r(p)

reghdfe pflow_w  dla_le20 crisis_dla_le20 ///
	dla_20_30 crisis_dla_20_30 dla_ge30 crisis_dla_ge30 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m2
qui:test crisis_dla_le20=crisis_dla_20_30
display r(p)
qui:test crisis_dla_le20=crisis_dla_ge30
display r(p)

reghdfe pflow_w crisis dla_le20 crisis_dla_le20 ///
	dla_20_30 crisis_dla_20_30 dla_ge30 crisis_dla_ge30 /// 
	wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m3
qui:test crisis_dla_le20=crisis_dla_20_30
display r(p)
qui:test crisis_dla_le20=crisis_dla_ge30
display r(p)
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w  dla_le20 crisis_dla_le20 ///
	dla_20_30 crisis_dla_20_30 dla_ge30 crisis_dla_ge30 /// 
	wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m4
qui:test crisis_dla_le20=crisis_dla_20_30
display r(p)
qui:test crisis_dla_le20=crisis_dla_ge30
display r(p)
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

*Output results
esttab m1 m2 m3 m4, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(crisis_dla_le20  crisis_dla_20_30 ///
	 crisis_dla_ge30 crisis_wla_le40  ///
	 crisis_wla_40_50  crisis_wla_ge50) ///
	 keep(crisis_dla_le20  crisis_dla_20_30 ///
	 crisis_dla_ge30 crisis_wla_le40  ///
	 crisis_wla_40_50  crisis_wla_ge50)
drop _est_m*	
clear





/*******************************************************************/
/*** Table 5: Summary statistics for the 2020 and 2008 MMF runs ***/
/*******************************************************************/

/*** Summary statistics for 2020 ***/
use data_crisis20_final
* Normal time
tabstat asset_d pflow_w wla_d   ///
	gsy safe risk cexpr bankaff age dla_d nav_d ///
	if w20 & ~crisis, ///
	stat(mean sd) long col(stat) 
* Crisis time
tabstat asset_d pflow_w wla_d   ///
	gsy safe risk cexpr bankaff age dla_d nav_d ///
	if w20 &crisis, ///
	stat(mean sd) long col(stat) 
clear


/*** Summary statistics for 2008 ***/
use data_crisis08_final
* Normal time
tabstat asset_d pflow_w wla_est   ///
	gsy safe risk cexpr bankaff age ///
	if w08 & ~crisis, ///
	stat(mean sd) long col(stat) 
* Crisis time
tabstat asset_d pflow_w wla_est  ///
	gsy safe risk cexpr bankaff age ///
	if w08 &crisis, ///
	stat(mean sd) long col(stat) 


	
	

/***********************************************************************/
/*** Table 6: Fund WLA levels and outflows during the 2008 MMF run***/
/***********************************************************************/

use data_crisis08_final

/*** Regressions ***/
reghdfe pflow_w crisis##c.wla_est pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) noabsorb
est store m1
reghdfe pflow_w crisis##c.wla_est pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) absorb(date)
est store m2
reghdfe pflow_w crisis wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) noabsorb
est store m3
reghdfe pflow_w crisis wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) absorb(date)
est store m4
reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) noabsorb
est store m5
reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age ///
	if w08, vce(cluster f_id date) absorb(date)
est store m6

*Output results
esttab m1 m2 m3 m4 m5 m6, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(1.crisis#c.wla_est crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high) ///
	 keep(1.crisis#c.wla_est crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high)
drop _est_m*	
clear







/**************************************************************/
/*** Table 7: Crisis outflows, WLA, and alternative channels***/
/**************************************************************/
use data_crisis20_final

/*** Regressions ***/
* NAV
reghdfe pflow_w pflow_lag_w ///
	crisis##c.wla_d_l2 crisis##c.nav_d_l2 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m1
reghdfe pflow_w pflow_lag_w ///
	crisis##c.wla_d_l2 crisis##c.nav_d_l2 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m2

* LT unsecured
reghdfe pflow_w pflow_lag_w crisis##c.wla_d_l2 ///
	crisis##c.share_uscpcd30 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m3
reghdfe pflow_w pflow_lag_w crisis##c.wla_d_l2 ///
	crisis##c.share_uscpcd30 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m4

* LT nonfinancial
reghdfe pflow_w pflow_lag_w crisis##c.wla_d_l2 ///
	crisis##c.share_nfcp30 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m5
reghdfe pflow_w pflow_lag_w crisis##c.wla_d_l2 ///
	crisis##c.share_nfcp30 ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m6

* Expense ratio
reghdfe pflow_w  ///
	 crisis##c.cexpr crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize  bankaff age ///
	if w20, vce(cluster f_id date) noabsorb
est store m7
reghdfe pflow_w  ///
	 crisis##c.cexpr crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize bankaff age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m8

* Bank affiliation
reghdfe pflow_w  ///
	 crisis##bankaff crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr  age ///
	if w20, vce(cluster f_id date) noabsorb
est store m9
reghdfe pflow_w  ///
	 crisis##bankaff crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize cexpr age ///
	if w20, vce(cluster f_id date) absorb(date)
est store m10

*Output results 
esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles  ///
	order(1.crisis 1.crisis#c.nav_d_l2  1.crisis#c.share_uscpcd30 ///
	1.crisis#c.share_nfcp30 1.crisis#c.cexpr 1.crisis#1.bankaff ///
	1.crisis#c.wla_d_l2)  ///
	keep(1.crisis 1.crisis#c.nav_d_l2  1.crisis#c.share_uscpcd30 ///
	1.crisis#c.share_nfcp30 1.crisis#c.cexpr 1.crisis#1.bankaff ///
	1.crisis#c.wla_d_l2)
drop _est_m*	
clear




/***************************************************************/
/*** Table 8: Fund WLA levels and crisis outflows: robustness ***/
/***************************************************************/

use data_crisis20_final

/*** Regressions ***/
reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	 ab_gsy safe risk logsize ///
	if w20, vce(cluster f_id date) absorb(date f_id)
est store m1

reghdfe pflow_w crisis##c.wla_d_l2 pflow_lag_w ///
	c.wla_d_l2##(1.PT_m2w 1.PT_m3w) ///
	 ab_gsy safe risk logsize ///
	if w20, vce(cluster f_id date) absorb(date f_id)
est store m2

reghdfe pflow_w crisis wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize  ///
	if w20, vce(cluster f_id date) absorb(date f_id)
est store m3
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w wla_le40 crisis_wla_le40 ///
	wla_40_50 crisis_wla_40_50 ///
	wla_ge50 crisis_wla_ge50 ///
        PT_m2w_wla_le40 PT_m2w_wla_40_50 PT_m2w_wla_ge50 ///
	PT_m3w_wla_le40 PT_m3w_wla_40_50 PT_m3w_wla_ge50 ///
	pflow_lag_w ab_gsy safe risk logsize ///
	if w20, vce(cluster f_id date) absorb(date f_id)
est store m4
qui:test crisis_wla_le40=crisis_wla_40_50
display r(p)
qui:test crisis_wla_le40=crisis_wla_ge50
display r(p)

reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	  pflow_lag_w ab_gsy safe risk logsize  ///
	  if w20, vce(cluster f_id date) absorb(date f_id)
est store m5
qui:test crisis_wla_low=crisis_wla_high
display r(p)

reghdfe pflow_w crisis wla_low crisis_wla_low ///
	wla_high crisis_wla_high ///
	PT_m2w_wla_low  PT_m2w_wla_high ///
	PT_m3w_wla_low  PT_m3w_wla_high ///
	 pflow_lag_w ab_gsy safe risk logsize  ///
	if w20, vce(cluster f_id date) absorb(date f_id)
est store m6
qui:test crisis_wla_low=crisis_wla_high
display r(p)

*Output results
esttab m1 m2 m3 m4 m5 m6, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles   ///
	order(1.crisis#c.wla_d_l2 crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high) ///
	 keep(1.crisis#c.wla_d_l2 crisis_wla_le40  crisis_wla_40_50 ///
	 crisis_wla_ge50 crisis_wla_low crisis_wla_high)
drop _est_m*	
clear





/***************************************************************/
/*** Table 9: Normalized distance of WLA to 30% and outflows ***/
/***************************************************************/
use data_crisis20_final
keep if w20

g wla_alt_1m=(wla_d_l2-30)/(wla_pre1m-30)
g crisis_wla_alt_1m=crisis*wla_alt_1m

foreach var in PT_m2w PT_m3w {
g `var'_wla_alt_1m=`var'*wla_alt_1m
}

foreach var in wla_alt_1m {
reghdfe pflow_w crisis `var' crisis_`var'  ///
		pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age, ///
		vce(cluster f_id date) absorb(date)
outreg2 using "table9.xls", label adjr2  ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, No) 

reghdfe pflow_w crisis `var' crisis_`var'  ///
		pflow_lag_w ab_gsy safe risk logsize, ///
		vce(cluster f_id date) absorb(date f_id) 
outreg2 using "table9.xls", label adjr2  ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, Yes) 

reghdfe pflow_w crisis `var' crisis_`var'  ///
		PT_m2w PT_m3w PT_m2w_wla_alt_1m PT_m3w_wla_alt_1m ///
		pflow_lag_w ab_gsy safe risk logsize, ///
		vce(cluster f_id date) absorb(date f_id) 
outreg2 using "table9.xls", label adjr2  ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, Yes, Parr. tread, Yes) 
}


egen wla_median=median(wla_alt_1m)
g wla_alt_1m_low=wla_alt_1m*cond(wla_alt_1m<=wla_median,1,0)
g wla_alt_1m_high=wla_alt_1m*cond(wla_alt_1m>wla_median,1,0)

g crisis_wla_alt_1m_low=crisis*wla_alt_1m_low
g crisis_wla_alt_1m_high=crisis*wla_alt_1m_high

foreach var in PT_m2w PT_m3w {
g `var'_wla_alt_1m_low=`var'*wla_alt_1m_low
g `var'_wla_alt_1m_high=`var'*wla_alt_1m_high
}

foreach var in wla_alt_1m {
reghdfe pflow_w crisis `var'_low crisis_`var'_low `var'_high crisis_`var'_high  ///
		pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age, ///
		vce(cluster f_id date) absorb(date)
test crisis_wla_alt_1m_low=crisis_wla_alt_1m_high
local test2_f=r(F)
local test2_p=r(p)
outreg2 using "table9.xls", label adjr2 ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, No, "F-stat: Crisis*L=Crisis*H", `test2_f', "p-value: Crisis*L=Crisis*H", `test2_p') cttop(H/L split at sample median)

reghdfe pflow_w crisis `var'_low crisis_`var'_low `var'_high crisis_`var'_high  ///
		pflow_lag_w ab_gsy safe risk logsize, ///
		vce(cluster f_id date) absorb(date f_id) 
test crisis_wla_alt_1m_low=crisis_wla_alt_1m_high
local test2_f=r(F)
local test2_p=r(p)
outreg2 using "table9.xls", label adjr2 ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, Yes, "F-stat: Crisis*L=Crisis*H", `test2_f', "p-value: Crisis*L=Crisis*H", `test2_p') cttop(H/L split at sample median)

reghdfe pflow_w crisis `var'_low crisis_`var'_low `var'_high crisis_`var'_high  ///
		PT_m2w PT_m3w PT_m2w_wla_alt_1m_low ///
		PT_m2w_wla_alt_1m_high PT_m3w_wla_alt_1m_low ///
		PT_m3w_wla_alt_1m_high ///
		pflow_lag_w ab_gsy safe risk logsize, ///
		vce(cluster f_id date) absorb(date f_id) 
test crisis_wla_alt_1m_low=crisis_wla_alt_1m_high
local test2_f=r(F)
local test2_p=r(p)
outreg2 using "table9.xls", label adjr2 ///
	drop(pflow_lag_w ab_gsy safe risk logsize cexpr bankaff age) ///
	addtext(Controls, Yes, Day FEs, Yes, Fund FEs, Yes, Parr. tread, Yes, "F-stat: Crisis*L=Crisis*H", `test2_f', "p-value: Crisis*L=Crisis*H", `test2_p') cttop(H/L split at sample median)
}
clear







/*****************************************************/
/*** Table 10: Crisis outflows and WLA, IV approach***/
/*****************************************************/

use data_crisis20_final

/*** regression ***/
eststo clear
eststo:  reghdfe pflow_w wla_d_l2  ab_gsy safe risk ///
	logsize bankaff cexpr age if crisis,  cluster(date) absorb(date) 

eststo: reghdfe pflow_w  wla_d_l2 pflow_lag_w ///
	ab_gsy safe risk logsize bankaff cexpr age  ///
	if crisis,  cluster(date) absorb(date) 

eststo: ivreghdfe pflow_w (wla_d_l2 = Dcumul_crisis) ab_gsy safe risk ///
	logsize bankaff cexpr age if crisis, cluster(date) absorb(date) 
	
eststo: ivreghdfe pflow_w (wla_d_l2 = Dcumul_crisis) pflow_lag_w ///
	ab_gsy safe risk logsize bankaff cexpr age ///
	if crisis, cluster(date) absorb(date) 

esttab using IV_wlacrisis.tex,  replace star(* 0.10 ** 0.05 *** 0.01) b(3) se(3) scalar(N widstat jp idp r2)
drop _est_*
clear







/*************************************************************/
/*** Table 11: MMFs' WLA deterioration and usage of the MMLF***/
/*************************************************************/

use data_mmlf_usage

/*** Regression ***/
reghdfe share logwmat  s_pct_nasst  s_yield_w inst ///
	if  eligible & cpcd  & mmlf_2w  , ///
	absorb(new_invtype) vce(cluster f_id cusip) 
est store m1
reghdfe share logwmat   s_pct_nasst  s_yield_w ///
	  ab_gsy safe risk logsize cexpr bankaff age ///
	 wla_d_change ///
	if  eligible & cpcd  & mmlf_2w & inst, ///
	absorb(new_invtype) vce(cluster f_id cusip) 
est store m2
reghdfe share logwmat   s_pct_nasst  s_yield_w ///
	 ab_gsy safe risk logsize cexpr bankaff age ///
	 wla_d_change crisisflow ///
	if  eligible & cpcd  & mmlf_2w  & inst, ///
	absorb(new_invtype) vce(cluster f_id cusip) 
est store m3
reghdfe share logwmat s_pct_nasst  s_yield_w ///
	if  eligible & cpcd  & mmlf_2w & inst & wla<., ///
	absorb(new_invtype f_id) vce(cluster f_id cusip) 	
est store m4

* Output results in Stata
esttab m1 m2 m3 m4, ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles ///
	order(logwmat inst wla_d_change  crisisflow) ///
	keep(logwmat inst wla_d_change  crisisflow) 
drop _est_*
clear








/****************************************************************/
/*** Table 12: Prime MMF flows around the launch of the MMLF***/
/****************************************************************/

use data_mmlf_final

/*** Regressions ***/
reghdfe pflow_w  i.mmlf pflow_lag_w wla_d_l2 ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if domestic & win_2w, vce(cluster f_id date) noabsorb
est store m1

reghdfe pflow_w mmlf##inst  pflow_lag_w wla_d_l2  ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if domestic & win_2w, vce(cluster f_id date) noabsorb
est store m2

reghdfe pflow_w mmlf##inst  pflow_lag_w wla_d_l2 ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if domestic & win_2w, vce(cluster f_id date) absorb(date)
est store m3

reghdfe pflow_w  i.mmlf pflow_lag_w wla_d_l2 ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if domestic & win_2w & inst, ///
	vce(cluster f_id date) noabsorb
est store m4

reghdfe pflow_w mmlf##c.wla_d_l2 pflow_lag_w ///
	ab_gsy safe risk logsize cexpr bankaff age ///
	if domestic & win_2w & inst, ///
	vce(cluster f_id date) absorb(date)
est store m5

* Output results in Stata
esttab m1 m2 m3 m4 m5 , ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles ///
	order(pflow_lag_w 1.mmlf  1.inst ///
	1.mmlf#1.inst  1.mmlf#c.wla_d_l2) ///
	keep(pflow_lag_w 1.mmlf  1.inst ///
	1.mmlf#1.inst  1.mmlf#c.wla_d_l2) 
drop _est_m*
clear





/****************************************************************/
/*** Table 13: The effect of the MMLF: domestic vs. offshore MMFs***/
/****************************************************************/

use data_mmlf_final

/*** Regressions ***/
reghdfe pflow_w mmlf##domestic ///
	if win_2w & inst, ///
	vce(cluster f_id date) noabsorb
est store m1
reghdfe pflow_w mmlf_w1##domestic   ///
	mmlf_w2##domestic  ///
	if win_2w & inst, ///
	vce(cluster f_id date) noabsorb
est store m2
reghdfe pflow_w mmlf_w1##domestic pflow_lag_w  ///
	mmlf_w2##domestic wla ab_gsy safe risk logsize ///
	if win_2w & inst, ///
	vce(cluster f_id date) noabsorb
est store m3
reghdfe pflow_w mmlf_w1##domestic pflow_lag_w  ///
	mmlf_w2##domestic wla ab_gsy safe risk logsize ///
	if win_2w & inst, ///
	vce(cluster f_id date) absorb(date)
est store m4

* Output results 
esttab m1 m2 m3 m4 , ///
	ar2 obslast star(* .10 ** .05 *** .01) b(%6.3f) ///
	se(%6.3f) nodepvars nomtitles ///
	order(pflow_lag_w 1.mmlf 1.domestic 1.mmlf#1.domestic ///
	1.mmlf_w1 1.mmlf_w1#1.domestic ///
	1.mmlf_w2 1.mmlf_w2#1.domestic) ///
	keep(pflow_lag_w 1.mmlf 1.domestic 1.mmlf#1.domestic ///
	1.mmlf_w1 1.mmlf_w1#1.domestic ///
	1.mmlf_w2 1.mmlf_w2#1.domestic)
drop _est_m*
clear
